package com.amigo.online.provider.merchant.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.amigo.online.common.base.service.BaseService;
import com.amigo.online.common.param.result.UserInfo;
import com.amigo.online.provider.merchant.common.GlobalController;
import com.amigo.online.provider.merchant.mapper.GoodsCollectMapper;
import com.amigo.online.provider.merchant.model.entity.GoodsCollect;
import com.amigo.online.provider.merchant.service.GoodsCollectService;

/**
 * <code>GoodsServiceImpl.java</code>
 * <p>
 * : 商品服务
 * </p>
 * <p>
 *
 * @author LuChen
 * @version 1.0
 * @company Amigo
 * @time 2018年12月15日 下午4:20:14
 * @lastUpdate 无
 * </p>
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class GoodsCollectServiceImpl extends BaseService<GoodsCollect> implements GoodsCollectService {

    @Autowired
    private GoodsCollectMapper goodsCollectMapper;


    @Override
    public boolean collectGoodById(Long id) {
        UserInfo user = GlobalController.getNowUser();
        Long userId = user.getId();
        GoodsCollect gc = new GoodsCollect();
        if (goodsCollectMapper.getCountByUserIdAndGoodsId(userId, id) > 0) {
            return true;
        }
        gc.setGoodsId(id);
        gc.setUserId(userId);
        gc.setDeleted(0);
        gc.setCreatedTime(System.currentTimeMillis() / 1000);
        goodsCollectMapper.insert(gc);
        return true;
    }

    @Override
    public boolean CancelCollectGoodById(List<Long> ids) {
        UserInfo user = GlobalController.getNowUser();
        Long userId = user.getId();
        if (ids.size() == 0) {
            return true;
        }
        Long nowTime = System.currentTimeMillis() / 1000;
        goodsCollectMapper.updateByIdList(userId, ids, nowTime);
        return true;
    }

}